import { API_SERVER } from '@/consts/config'
import * as http from './utils/http'
import getTokenByAppId from './utils/get-token-by-app-id'

export default {
  /**
   * 查询所有已登记的延保纪录列表
   * @param  Object 查询参数
   * @return status
   */
  getWarrantyList (appId, params) {
    return http.post(
      `http://${API_SERVER.warranty}/module/warranty/${appId}/api/warranty/list`, params, getTokenByAppId(appId)
    )
  },

  /**
   * 查询维修工单
   * @param  Object 查询参数
   * @return status
   */
  getWorkOrders (appId, params) {
    return http.post(
      `http://${API_SERVER.warranty}/module/warranty/${appId}/api/work_orders/list`, params, getTokenByAppId(appId)
    )
  },

  /**
   * 查询维修详情
   * @param  Object 查询参数
   * @return status
   */
  getRepairDetailList (appId, params) {
    return http.post(
      `http://${API_SERVER.warranty}/module/warranty/${appId}/api/repair_details/list`, params, getTokenByAppId(appId)
    )
  },
  /**
   * 添加维修详情
   * @param  Object 查询参数
   * @return status
   */
  addWorkOrder (appId, params) {
    return http.post(
      `http://${API_SERVER.warranty}/module/warranty/${appId}/api/work_orders/save`, params, getTokenByAppId(appId)
    )
  },
  /**
   * 编辑维修详情
   * @param  Object 查询参数
   * @return status
   */
  updateWorkOrder (appId, repairId, params) {
    return http.put(
      `http://${API_SERVER.warranty}/module/warranty/${appId}/api/work_orders/update/${repairId}`, params, getTokenByAppId(appId)
    )
  },
  /**
   * 删除维修详情
   * @param  Object 查询参数
   * @return status
   */
  delWorkOrder (appId, repairId) {
    return http.put(
      `http://${API_SERVER.warranty}/module/warranty/${appId}/api/work_orders/delete/${repairId}`, {}, getTokenByAppId(appId)
    )
  },
  /**
   * 维修概览
   * @param  Object 查询参数
   * @return status
   */
  getSummary (appId) {
    return http.post(
      `http://${API_SERVER.warranty}/module/warranty/${appId}/api/work_orders/group`, {}, getTokenByAppId(appId)
    )
  },

  /**
   * 查询网点信息
   * @param  Object 查询参数
   * @return status
   */
  getBranchList (appId, params) {
    return http.post(
      `http://${API_SERVER.warranty}/module/warranty/${appId}/api/branch/list`, params, getTokenByAppId(appId)
    )
  },

  /**
   * 增加网点信息
   * @param  Object 查询参数
   * @return status
   */
  AddBranch (appId, params) {
    return http.post(
      `http://${API_SERVER.warranty}/module/warranty/${appId}/api/branch/save`, params, getTokenByAppId(appId)
    )
  },

   /**
    * 修改网点信息
    * @param  Object 查询参数
    * @return status
    */
  UpdateBranch (appId, params, branchId) {
    return http.put(
      `http://${API_SERVER.warranty}/module/warranty/${appId}/api/branch/update/${branchId}`, params, getTokenByAppId(appId)
    )
  },

  /**
   * 删除网点信息
   * @param  Object 查询参数
   * @param  String 网点ID
   * @return status
   */
  deleteBranch (appId, branchId) {
    return http.del(
      `http://${API_SERVER.warranty}/module/warranty/${appId}/api/branch/delete/${branchId}`, getTokenByAppId(appId)
    )
  },

  /**
   * 查询维修点员工列表
   * @param  Object 查询参数
   * @return status
   */
  getStaffs (appId, params) {
    return http.post(
     `http://${API_SERVER.warranty}/module/warranty/${appId}/api/outlet_staffs/list`, params, getTokenByAppId(appId)
   )
  },

  /**
  * 增加维修点员工资料
  * @param  Object 查询参数
  * @return status
  */
  AddBranchStaffs (appId, params) {
    return http.post(
      `http://${API_SERVER.warranty}/module/warranty/${appId}/api/outlet_staffs/save`, params, getTokenByAppId(appId)
    )
  },

  /**
  * 修改维修点员工资料
  * @param  Object 查询参数
  * @return status
  */
  UpdateBranchStaffs (appId, staffId, params) {
    return http.put(
      `http://${API_SERVER.warranty}/module/warranty/${appId}/api/outlet_staffs/update/${staffId}`, params, getTokenByAppId(appId)
    )
  },

  /**
   * 删除维修点员工资料
   * @param  Object 查询参数
   * @return status
   */
  deleteStaff (appId, staffId) {
    return http.del(
      `http://${API_SERVER.warranty}/module/warranty/${appId}/api/outlet_staffs/delete/${staffId}`, getTokenByAppId(appId)
    )
  },
  /**
   * 查询标签
   * @param  {string} appId, {string} token {object} params
   * @return promise
   */
  getLabel (appId) {
    return http.post(
      `http://${API_SERVER.warranty}/module/warranty/${appId}/api/label/list`, {}, getTokenByAppId(appId)
    )
  },

  /**
   * 添加标签
   * @param  {string} appId, {string} token {object} params
   * @return promise
   */
  saveLabel (appId, params) {
    return http.post(
      `http://${API_SERVER.warranty}/module/warranty/${appId}/api/label/save`, params, getTokenByAppId(appId)
    )
  },

  getCard (appId, params) {
    return http.post(
      `http://${API_SERVER.warranty}/module/warranty/${appId}/api/card/list`, params, getTokenByAppId(appId)
    )
  },
  analysis (appId, params) {
    return http.post(
      `http://${API_SERVER.warranty}/module/warranty/${appId}/api/work_orders/analysis`, params, getTokenByAppId(appId)
    )
  },
  staffSummary (appId, params) {
    return http.post(
      `http://${API_SERVER.warranty}/module/warranty/${appId}/api/outlet_staffs/group`, params, getTokenByAppId(appId)
    )
  }
}
